package cn.edu.neusoft.wuguangsheng.flowerimpression.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.Utils.TimeUtils;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.OtherUserInfoActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.GoodsCommentBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.service.Service;

public class GoodsCommentAdapter extends BaseAdapter<GoodsCommentBean> {
    String times;

    public GoodsCommentAdapter(Context context, List<GoodsCommentBean> items, int layoutResourse) {
        super(context, items, layoutResourse);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(context).inflate(layoutResourse,parent,false);
        KnowCommentViewHolder knowCommentViewHolder = new KnowCommentViewHolder(itemView);
        return knowCommentViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        KnowCommentViewHolder knowCommentViewHolder=(KnowCommentViewHolder) holder;
        GoodsCommentBean goodsCommentBean=items.get(position);

        final String name = goodsCommentBean.getUser_nickname();
        final String content = goodsCommentBean.getOrc_content();
        final String time = goodsCommentBean.getOrc_time();
        final String img = Service.BASE_URL+"flower_impression/public/uploads/"+goodsCommentBean.getUser_photo();

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = simpleDateFormat.parse(time);
            times = TimeUtils.getTimeFormatText(date);
        }catch (Exception e){
            e.printStackTrace();
        }

        knowCommentViewHolder.knowcomment_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intentc = new Intent(context, OtherUserInfoActivity.class);
                context.startActivity(intentc);
            }
        });

        knowCommentViewHolder.knowcomment_username.setText(name);
        knowCommentViewHolder.knowcomment_content.setText(content);
        knowCommentViewHolder.knowcomment_time.setText(times);
        Picasso.with(context).load(img).into(knowCommentViewHolder.knowcomment_img);



    }
}
